<div id="<?=$name;?>" >

<?= $field;?>

<a href="#" id="add_<?= $name; ?>" <?php if($pos == $max) echo "style='display: none;'"?>>Add <?= $properties['title'];?></a>
<a href="#" id="delete_<?= $name; ?>" <?php if($pos == 0) echo "style='display: none;'"?>>Delete <?= $properties['title'];?></a>
</div>

<script type="text/javascript">
	$(document).ready(function(){
		<?php for($i=$pos+1; $i<=$max; $i++):?>
		$("#<?=	$name.$i?>").hide();
		<?php endfor;?>

		var addpos_<?= $name;?> = <?= $pos+1;?>;
		$("#add_<?= $name; ?>").click(function(){
			$("#<?= $name?>" + addpos_<?= $name;?>).show();
			
			if(addpos_<?= $name;?> == <?= $max?>){
				$("#add_<?= $name; ?>").hide();
			}
			addpos_<?= $name;?>++;

			$("#delete_<?= $name; ?>").show();

			return false;
		})

		$("#delete_<?= $name; ?>").click(function(){
			if(addpos_<?= $name;?> > 1){
				addpos_<?= $name;?>--;
				$("#<?= $name?>" + addpos_<?= $name;?>).hide();
				if(addpos_<?= $name;?> == 1){
					$("#delete_<?= $name; ?>").hide();
				}

				$("#add_<?= $name; ?>").show();
			}

			return false;
		})
	})
</script>